import Mock from 'mockjs2'
import { builder } from '../util'

const totalCount = 5701

const status = [
  0, // 未读
  1 // 已读
]

const messageList = () => {
  const result = []
  const pageNo = 0
  const pageSize = 30
  const totalPage = Math.ceil(totalCount / pageSize)
  const next = (pageNo >= totalPage ? (totalCount % pageSize) : pageSize) + 1

  for (let i = 1; i < next; i++) {
    result.push({
      id: Mock.mock('@id'),
      title: Mock.mock('@String(15)'),
      created_at: Mock.mock('@datetime'),
      msg_type: '系统通知',
      status: status[i % 2]
    })
  }

  return builder({
    pageSize: pageSize,
    pageNo: pageNo,
    totalCount: totalCount,
    totalPage: totalPage,
    data: result
  })
}

Mock.mock(/\/message/, 'get', messageList)
